package com.huawei.petapp2.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.huawei.petapp2.R;
import com.huawei.petapp2.entity.ImageBean;

import java.util.List;

public class PetImageAdapter extends RecyclerView.Adapter<PetImageAdapter.ItemViewHolder> {

    private List<ImageBean> mItems;

    public PetImageAdapter(List<ImageBean> mItems) {
        this.mItems = mItems;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_pet_image_item, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) {
        holder.textView.setText(mItems.get(position).getName());
        holder.imageView.setImageResource(mItems.get(position).getPicture());
    }

    @Override
    public int getItemCount() {
        return mItems == null ? 0 : mItems.size();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        ImageView imageView;

        ItemViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.pet_image_item_name);
            imageView = itemView.findViewById(R.id.pet_image_item_imageview);
        }
    }
}